package Buffer2;

import java.io.*;

public class Test {
    public static void main(String[] args)throws  Exception{
        //获取创建数据源路径对象
        File srcFolder = new File("E:\\itcast");
        //获取数据源路径名称
        String srecname = srcFolder.getName();
        //创建目的地路径对象
        File destFolder = new File("IO", srecname);
        if (!destFolder.exists()) {
            destFolder.mkdir();
        }
        File[] files = srcFolder.listFiles();
        for (File file : files) {
            String name = file.getName();
            //创建目的地文件对象，目的地路径+每一个文件名名称
            File destFile = new File(destFolder, name);
            copyFile( file, destFile);
        }

    }
    public static void copyFile(File file, File destFile) throws Exception {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
        byte[] bytes = new byte[1024];
        int ten;
        while ((ten = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, ten);
        }
    }
}
